Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RootNodeOwner.OwnerImpl.onRequestRelayout to only schedule layout, not measure #1355

Merged
merged 1 commit into from
May 13, 2024

Conversation

m-sasha
Copy link

@m-sasha m-sasha commented May 13, 2024

Currently, OwnerImpl.onRequestRelayout simply calls onRequestMeasure. This means that when a layout scope is invalidated, we will schedule a measuring too.

This is unnecessary, and in some cases (when the measure scope invalidates the layout scope) causes infinite re-layout.

Fixes JetBrains/compose-multiplatform#4760

Testing

  • Added new unit tests
  • Tested the user-provided code, as well as a reproducer:
fun main() = singleWindowApplication {
    val state = remember { mutableStateOf(1) }
    Layout(
        measurePolicy = { measurables, constraints ->
            val measurable = measurables.first()
            val placeable = measurable.measure(constraints)
            val prevValue = Snapshot.withoutReadObservation {
                state.value
            }
            state.value = prevValue+1
            layout(100, 100) {
                state.value  // Read the state value!
                placeable.placeRelative(0, 0)
            }
        },
        content = {
            Text("Hello")
        }
    )
}

This could be tested by QA

Release Notes

Fixes - Multiple Platforms

  • Fix endless re-layout when layout is invalidated by measure, which includes measuring TextField(singleLine=true) with IntrinsicSize.

@m-sasha m-sasha requested a review from igordmn May 13, 2024 11:31
@m-sasha
Copy link
Author

m-sasha commented May 13, 2024

I've also renamed SnapshotInvalidationTracker.requestLayout to requestMeasureAndLayout (and the corresponding flag), because that's what it actually does.

@m-sasha m-sasha force-pushed the m-sasha/fix-infinite-relayout branch from 55e6e05 to 99e91a7 Compare May 13, 2024 11:45
@m-sasha m-sasha force-pushed the m-sasha/fix-infinite-relayout branch from 99e91a7 to ec35b33 Compare May 13, 2024 13:08
@m-sasha m-sasha merged commit cb943db into jb-main May 13, 2024
6 checks passed
@m-sasha m-sasha deleted the m-sasha/fix-infinite-relayout branch May 13, 2024 14:38
MatkovIvan pushed a commit that referenced this pull request May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Endless re-layout of TextField with singleLine = true and intrinsic measurement
3 participants